package handler

import (
	"context"
	"fmt"
	"zg6/o2-o-takeaway-backend-system/common/global"
	"zg6/o2-o-takeaway-backend-system/common/models"
	"zg6/o2-o-takeaway-backend-system/common/proto/notices"
)

type Server struct {
	notices.UnimplementedNoticeSrvServer
}

func (s *Server) SendNotice(ctx context.Context, req *notices.SendNoticeRequest) (*notices.Response, error) {

	notice := models.Notices{
		Title:      req.Title,
		Content:    req.Content,
		ReceiveId:  req.ReceiveId,
		NoticeType: uint8(req.Types),
		Client:     uint8(req.Client),
	}
	if err := global.DB.Create(&notice).Error; err != nil {
		return nil, fmt.Errorf("发送通知失败：%s", err)
	}
	return &notices.Response{}, nil
}
